﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;

namespace LightningForms
{
    public class Currency : BaseTextControl
    {
        private string script()
        {
            return "_lf.AddControl({ Control: '#_R_', Type: _lf.Type.CURRENCY });".Replace("_R_", this.ClientID);
        }

        public new decimal? MinValue
        {
            get { return string.IsNullOrEmpty(base.MinValue) ? null : new Nullable<decimal>(Convert.ToDecimal(base.MinValue)); }
            set { if(value.HasValue) base.MinValue = Convert.ToString(value.Value); }
        }
        public new decimal? MaxValue
        {
            get { return string.IsNullOrEmpty(base.MaxValue) ? null : new Nullable<decimal>(Convert.ToDecimal(base.MaxValue)); }
            set { if (value.HasValue) base.MaxValue = Convert.ToString(value.Value); }
        }

        public Currency()
        {
            this.DataType = ValidationDataType.Currency;
        }

        protected override void OnPreRender(EventArgs e)
        {
            this.Page.ClientScript.RegisterStartupScript(this.GetType(), this.ClientID, script(), true);
            base.OnPreRender(e);
        }
    }
}